package LinkedList.删除节点;

import LinkedList.ListNode;

public class Test {
    public ListNode removeNthFromEnd(ListNode head, int n) {

        ListNode l1 = head;
        int count = 0;

        while(l1 != null) {
            count++;
            l1 = l1.next;
        }

        if(count == n) {
            return head.next;
        }

        int go = count - n - 1;

        ListNode cur = head;

        while(go != 0) {
            cur = cur.next;
            go--;
        }


        cur.next = cur.next.next;


        return head;

    }
}
